﻿using System;
using System.Data;
using System.Windows.Forms;
using Infragistics.Win.UltraWinGrid;
using QUANLYSINHVIEN.Sevice;

namespace QUANLYSINHVIEN
{
    public partial class frmLop : Form
    {
        ILopService hs = new ILopService();
        UltraCombo uc_lop = new UltraCombo();
        public frmLop()
        {
            InitializeComponent();
            Load();
            LoadGridView();
        }
        public void Load()
        {
            cboLop.DataSource = hs.LoadLop();
            cboLop.DisplayMember = "TenLop";
            cboLop.ValueMember = "MaLop";
            
        }
        public void Loadcbo()
        {
           // uc_lop.BindingContext = this.BindingContext;
            uc_lop.DataSource = hs.LoadLop();
            uc_lop.DisplayMember = "TenLop";
            uc_lop.ValueMember = "MaLop";

            cboTest.DataSource = hs.LoadLop();
            cboTest.DisplayMember = "TenLop";
            cboTest.ValueMember = "MaLop";
        }
        private void cboLop_Click(object sender, EventArgs e)
        {
            if(!cboLop.Text.ToString().Equals("")){
                lbDemo.Text = cboLop.Value.ToString();// Lấy ra value
            }
            if (!cboTest.Text.ToString().Equals(""))
            {
                lbTest.Text = cboTest.SelectedValue.ToString();// Lấy ra value
            }
        }
        public DataTable gettable()
        {
            DataTable table = new DataTable();
            table.Columns.Add("ID", typeof(int));
            table.Columns.Add("MaLop", typeof(string));
            table.Columns.Add("TenLop", typeof(string));
            table.Columns.Add("MaKhoa", typeof(string));

            table.Rows.Add(1,null,"Ma1",null);
            table.Rows.Add(1, null, "Ma1", null);
            return table;
        }
        public void LoadGridView()
        {
            Loadcbo();
            uGLop.DataSource = gettable();
            //uGLop.DisplayLayout.Override.ActiveCellAppearance.Reset();
            //uGLop.DisplayLayout.Override.ActiveRowAppearance.Reset();
            //this.uGLop.DisplayLayout.Bands[0].RowLayoutStyle = RowLayoutStyle.ColumnLayout;
            //this.uGLop.DisplayLayout.Bands[0].Override.AllowRowLayoutLabelSizing = RowLayoutSizing.Both;
            //this.uGLop.SyncWithCurrencyManager = false;
        }
        /// <summary>
        /// load combobox vào GridView, có thể gán bằng combobox kéo vào
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uGLop_InitializeLayout(object sender, InitializeLayoutEventArgs e)
        {
            e.Layout.Bands[0].Columns[2].EditorComponent = uc_lop;
            //for (int i = 0; i < e.Layout.Bands[0].Columns.Count; i++)
            //{
            //    e.Layout.Bands[0].Columns[i].CellAppearance.TextHAlign = Infragistics.Win.HAlign.Center;
            //}
        }
    }
}
